#pragma once

enum RFAlg{BEZSUB=0, BEZSUBALL, BEZCLIP, BEZCLIPALL, KNOTINSERT, KNOTINSERTALL, KNOTINSERTBEZ, KNOTINSERTBEZALL, MP, AA};

class RootFinder
{
public:
	RootFinder(void);
	~RootFinder(void);

	RootFinder(int dim, int* deg, bool findAll);

	void SetAlg(RFAlg alg){mRFAlg=alg;}

	void FindRoot(float* f, float* uIn, float* uOut, float* root, int* rootN);

	void PolynomailFit(float *f, float* u0, float* u1, float* fitMat, float *coeff);

private:
	RFAlg mRFAlg;

	//WorkSpace for all the algorithm, save the time for allocation memory frequently.
	float* mWork;
	void InitWorkSpace();

	void InitFitMatrix(int degSum);
	float* mBezFitMat;
	float* mPowFitMat;

	int mDim;
	int mDeg[3];
	int mDegSum;
};